<!--
 * @Description: 车主关键信息变更
 * @Autor: 刘诗文
 * @Date: 2020-11-13 10:01:45
 * @LastEditors: 马毅
 * @LastEditTime: 2021-05-19 16:02:37
-->
<template>
  <div>
    <TopFilter :list="topFilterList" :cols="3" :labelWidth="105" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      ref="table"
      selectionType="single"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      columnsRef="keyInfoChangeOfOwnerlsw"
      :onColumnsChange="columns => (this.columns = columns)"
      :height="auto"
    >
      <template slot="controls">
        <el-button size="small" type="primary" icon="el-icon-plus" @click="() => this.openHandler('add', {})">新增变更</el-button>
        <AjaxButton size="small" type="primary" icon="el-icon-download" :click="ownerExportData">导出</AjaxButton>
      </template>
    </FilterTable>
    <Drawer :visible.sync="actions.visible" :title="actions.title" width="60%" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <addKeyInfoChangePanel :type.sync="actions.type" :formData="this.resData" @close="closeHandler" />
    </Drawer>
    <BaseDialog :visible.sync="checkActions.visible" :title="checkActions.title" width="60%" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <keyInfoCheckDetail :type.sync="checkActions.type" :formData="this.resData" @close="checkCloseHandler" />
    </BaseDialog>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import addKeyInfoChangePanel from './addKeyInfoChangePanel';
import keyInfoCheckDetail from './keyInfoCheckDetail';
import { exportExcelFile } from '@/utils/index';
import { getAllUser } from '@/api/customerRepair/afterSaleVisit/resultEntry';
import { getOwnerInfo, getOwnerExcelList, getProvince, getCitys, getDistrict, getRegion } from '@/api/customerRepair/customerInfo/ownerVehicleManagement';
import { getKeyInfoChangeList, getKeyInfoChangeExport } from '@/api/customerRepair/vehicleOwnerManagement/vehicleChange';
export default {
  name: 'keyInfoChangeOfOwner',
  components: {
    addKeyInfoChangePanel,
    keyInfoCheckDetail
  },
  mixins: [dictionary],
  data() {
    this.BaseTable = null;
    this.type = '';
    this.resData = {};
    this.title = '';
    // isHidden: 'none';
    return {
      topFilterList: this.createTopFilterList(),
      fetchApi: getKeyInfoChangeList,
      fetchParams: { pageNum: 1, xhrAbort: true },
      columns: this.createTableColumns(),
      actions: { title: '', visible: false, type: '' },
      checkActions: { title: '', visible: false, type: '' }
    };
  },
  created() {
    // 获取所有用户
    this.getAllUser();
    // this.getProvine();
  },
  mounted() {
    this.BaseTable = this.$refs.table;
    // this.menuUserAction();
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '证件号',
          fieldName: 'certificateNo'
        },
        {
          type: 'INPUT',
          label: '车主姓名',
          fieldName: 'ownerName'
        },
        {
          type: 'INPUT',
          label: '车主手机号',
          fieldName: 'mobile',
          placeholder: '请输入...'
        },
        {
          type: 'RANGE_DATE',
          label: '变更日期',
          style: { minWidth: '200px' },
          fieldName: 'changeTimeBegin|changeTimeEnd'
        },
        {
          type: 'SELECT',
          label: '审核状态',
          fieldName: 'status',
          itemList: this.createDictList(1261)
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" disabled={props.row.status === 12611001 && props.row.isIfUpload == 1 ? true : false} onClick={() => this.openHandler('edit', props.row)}>
                  编辑
                </el-button>
                <el-divider direction="vertical" />
                <el-button size="mini" type="text" onClick={() => this.openHandler('check', props.row)}>
                  明细
                </el-button>
              </div>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '车主编号',
          dataIndex: 'ownerNo',
          width: 120,
          showOverflowTooltip: true
        },
        {
          title: '客户性质',
          dataIndex: 'ownerProperty',
          width: 150,
          showOverflowTooltip: true,
          render: props => {
            return <span>{this.createDictText(props.row.ownerProperty, 8011)}</span>;
          }
        },
        {
          title: '车主姓名',
          dataIndex: 'newOwnerName',
          width: 150,
          showOverflowTooltip: true
        },
        {
          title: '证件号',
          dataIndex: 'certificateNo',
          width: 130,
          showOverflowTooltip: true
        },
        {
          title: '车主手机',
          dataIndex: 'mobile',
          width: 100,
          showOverflowTooltip: true
        },
        {
          title: '操作人',
          dataIndex: 'operator',
          width: 120,
          showOverflowTooltip: true
        },
        {
          title: '变更申请时间',
          dataIndex: 'changeTime',
          width: 150
        },
        {
          title: '审核时间',
          dataIndex: 'examDate',
          width: 150
        },
        {
          title: '审核结果',
          dataIndex: 'status',
          width: 90,
          showOverflowTooltip: true,
          render: props => {
            return <span>{this.createDictText(props.row.status, 1261)}</span>;
          }
        },
        {
          title: '是否上传成功',
          dataIndex: 'isIfUpload',
          showOverflowTooltip: true,
          dictItems: [
            { text: '否', value: 0 },
            { text: '是', value: 1 }
          ]
        },
        {
          title: '审核信息',
          dataIndex: 'remarks',
          showOverflowTooltip: true
        }
      ];
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val, { xhrAbort: false });
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.$refs.table.$refs.pageTable.EXECUTE_RESET_HEIGHT();
      });
    },

    //新建变更车联关键信息界面
    openHandler(type, val) {
      if (type === 'add') {
        this.actions = { title: '新增车主变更', visible: true, type: 'add' };
      } else if (type === 'edit') {
        if (val.status === 12611003 || (val.isIfUpload == 0 && val.status === 12611001)) {
          this.actions = { title: '编辑车主变更', visible: true, type: 'edit' };
        } else {
          this.actions = { title: '车主变更明细', visible: true, type: 'show' };
        }
        this.resData = val;
      } else if (type === 'check') {
        this.checkActions = { title: '审核信息', visible: true, type: 'check' };
        this.resData = val;
      }
    },
    // 关闭新建界面
    closeHandler(refesh) {
      this.actions.visible = false;
      refesh && (this.fetchParams = { ...this.fetchParams });
    },
    // 关闭审核明细界面
    checkCloseHandler(refesh) {
      this.checkActions.visible = false;
      refesh && (this.fetchParams = { ...this.fetchParams });
    },
    // 所有用户
    async getAllUser() {
      const res = await getAllUser();
      if (res.resultCode === 200) {
        if (res.errMsg) {
          return notifyAction(res.errMsg, 'error');
        } else {
          this.columns.find(item => item.dataIndex === 'operator').dictItems = res.data.map(x => ({ value: x.userId + '', text: x.employeeName }));
        }
      }
    },
    // 下载
    async ownerExportData() {
      await getKeyInfoChangeExport(this.fetchParams).then(res => {
        if (res.status !== 'failure') {
          exportExcelFile(res.data, '车主关键信息变更');
        } else {
          notifyAction('导出失败', 'error');
        }
      });
    }
  }
};
</script>
<style lang="less" scoped></style>
